{{include file="public/header" /}}

<!-- header nav -->
{{include file="public/header_nav" /}}

<!-- conntent start  -->
<div class="am-g inside create">
    <form class="am-form am-form-horizontal form-validation" method="post" action="{{:MyUrl('install/index/confirm')}}" request-type="ajax-fun" request-value="FormBackConfirm" timeout="60000">
        <div class="am-alert am-radius" data-am-alert>
            <button type="button" class="am-close">&times;</button>
            <p class="am-text-sm">
                <strong>温馨提示</strong>
            </p>
            <div class="am-padding-left-sm am-text-xs am-margin-top-xs">
                <p>建议采用utf8mb4编码、MySQL版本5.6或5.7</p>
                {{if !empty($charset_type_list)}}
                    {{foreach $charset_type_list as $v}}
                        <p>{{$v.charset}}编码、MySQL版本需 {{$v.version}} 及以上版本 （{{$v.collate}}）</p>
                    {{/foreach}}
                {{/if}}
                <p class="am-margin-top-xs am-text-danger">填写的信息中不要包含【&nbsp;&nbsp;&nbsp;'&nbsp;&nbsp;&nbsp;&nbsp;"&nbsp;&nbsp;&nbsp;&nbsp;\&nbsp;&nbsp;&nbsp;&nbsp;<span><</span>?php&nbsp;&nbsp;&nbsp;&nbsp;<span><</span>?&nbsp;&nbsp;&nbsp;&nbsp;?<span>></span>&nbsp;&nbsp;&nbsp;&nbsp;<&nbsp;&nbsp;&nbsp;&nbsp;>&nbsp;&nbsp;&nbsp;&nbsp;&&nbsp;&nbsp;&nbsp;】类特殊符号</p>
            </div>
        </div>

        <div class="am-panel am-panel-default am-radius">
            <div class="am-panel-hd">
                <h2 class="am-margin-0">数据库配置信息</h2>
            </div>
            <div class="am-panel-bd">
                <div class="am-form-group">
                    <label class="am-u-sm-2 am-form-label">数据库类型</label>
                    <div class="am-u-sm-10">
                        <input type="text" name="DB_TYPE" placeholder="数据库类型" value="mysql" class="am-radius am-input-sm" readonly data-validation-message="请选择数据库类型" required />
                    </div>
                </div>
                <div class="am-form-group am-form-select">
                    <label class="am-u-sm-2 am-form-label">数据库编码</label>
                    <div class="am-u-sm-10">
                        <select class="am-input-sm am-radius chosen-select" name="DB_CHARSET" data-validation-message="请选择数据编码" required>
                            {{if !empty($charset_type_list)}}
                                {{foreach $charset_type_list as $v}}
                                    <option value="{{$v.charset}}">{{$v.charset}} - {{$v.collate}} （mysql版本>={{$v.version}}）</option>
                                {{/foreach}}
                            {{/if}}
                        </select>
                    </div>
                </div>
                <div class="am-form-group">
                    <label class="am-u-sm-2 am-form-label">数据库服务器</label>
                    <div class="am-u-sm-10">
                        <input type="text" name="DB_HOST" placeholder="数据库服务器" value="127.0.0.1" class="am-radius am-input-sm" data-validation-message="请填写数据库服务器地址" required />
                    </div>
                </div>
                <div class="am-form-group">
                    <label class="am-u-sm-2 am-form-label">数据库端口</label>
                    <div class="am-u-sm-10">
                        <input type="number" name="DB_PORT" placeholder="数据库端口" value="3306" class="am-radius am-input-sm" data-validation-message="请填写数据库端口" required />
                    </div>
                </div>
                <div class="am-form-group">
                    <label class="am-u-sm-2 am-form-label">数据库名</label>
                    <div class="am-u-sm-10">
                        <input type="text" name="DB_NAME" placeholder="数据库名" value="" class="am-radius am-input-sm" data-validation-message="请填写数据库名" required />
                    </div>
                </div>
                <div class="am-form-group">
                    <label class="am-u-sm-2 am-form-label">数据库用户名</label>
                    <div class="am-u-sm-10">
                        <input type="text" name="DB_USER" placeholder="数据库用户名" value="" class="am-radius am-input-sm" data-validation-message="请填写数据库用户名" required />
                    </div>
                </div>
                <div class="am-form-group">
                    <label class="am-u-sm-2 am-form-label">数据库密码</label>
                    <div class="am-u-sm-10">
                        <input type="text" name="DB_PWD" placeholder="数据库密码" value="" class="am-radius am-input-sm" data-validation-message="请填写数据库密码" required />
                    </div>
                </div>
                <div class="am-form-group">
                    <label class="am-u-sm-2 am-form-label">数据表前缀</label>
                    <div class="am-u-sm-10">
                        <input type="text" name="DB_PREFIX" placeholder="数据表前缀" value="sxo_" class="am-radius am-input-sm" data-validation-message="请填写数据表前缀" required />
                    </div>
                </div>
            </div>
        </div>

        <div class="am-panel am-panel-default am-radius">
            <div class="am-panel-hd">
                <h2 class="am-margin-0">管理员账号信息</h2>
            </div>
            <div class="am-panel-bd">
                <div class="am-form-group">
                    <label class="am-u-sm-2 am-form-label">管理员账号</label>
                    <div class="am-u-sm-10">
                        <input type="text" name="ADMIN_USERNAME" placeholder="账号格式2~18个字符之间" value="admin" minlength="2" maxlength="18" class="am-radius am-input-sm" data-validation-message="请填写管理员账号、格式2~18个字符之间" required />
                    </div>
                </div>
                <div class="am-form-group">
                    <label class="am-u-sm-2 am-form-label">管理员密码</label>
                    <div class="am-u-sm-10">
                        <input type="text" name="ADMIN_PWD" placeholder="密码格式6~18个字符之间" value="" minlength="6" maxlength="18" class="am-radius am-input-sm" data-validation-message="请填写管理员密码、格式6~18个字符之间" required />
                    </div>
                </div>
            </div>
        </div>

        <div class="agree ongoing-button">
            <a href="{{:MyUrl('install/index/check')}}" class="am-btn am-btn-secondary am-radius am-btn-xs">
                <i class="am-icon-arrow-left"></i>
                <span>上一步</span>
            </a>
            <button type="submit" class="am-btn am-btn-success am-radius am-btn-xs btn-loading-example" data-am-loading="{spinner:'circle-o-notch', loadingText:'确认安装'}">
                <i class="am-icon-check"></i>
                <span>确认安装</span>
            </button>
        </div>
    </form>
</div>
<!-- conntent end  -->

{{include file="public/footer" /}}
<script type="text/javascript">
function FormBackConfirm(e)
{
    var $button = $('form.form-validation button[type="submit"]');
    if(e.code == 0)
    {
        $.AMUI.progress.start();
        $.ajax({
            url: "{{:MyUrl('install/index/add')}}",
            type: 'POST',
            dataType: "json",
            timeout: 60000,
            data: GetFormVal('form.form-validation', true),
            success: function(res)
            {
                $.AMUI.progress.done();
                if(res.code == 0)
                {
                    Prompt(res.msg, 'success');
                    setTimeout(function()
                    {
                        window.location.href = "{{:MyUrl('install/index/successful')}}";
                    }, 1500);
                } else {
                    Prompt(res.msg);
                    $button.button('reset');
                }
            },
            error: function(xhr, type)
            {
                $button.button('reset');
                $.AMUI.progress.done();
                Prompt(HtmlToString(xhr.responseText) || '异常错误', null, 30);
            }
        });
    } else {
        $button.button('reset');
        Prompt(e.msg)
    }
}
</script>